from mycelery.main import app
from skylark_yun.libs.tencent.sms import TencentSMS
from skylark_yun.settings import constants
import logging

log = logging.getLogger('django')


@app.task(name='send_sms')
def send_sms(phone, sms_code):
    try:
        # 4. 调用短信SDK，发送短信
        sms_client = TencentSMS()
        result = sms_client.send_sms(phone_number=phone, template_param_set=sms_code)
        if not result:
            log.error(f"短信发送失败，手机号：{phone}")
    except Exception as e:
        log.error(f"短信发送异常，手机号：{phone}，异常信息：{e}")